import numpy as np
import pandas as pd

def main():

	# NOTE: Set these parameters to run desired analysis
	num_bootstrap_samples <- 50
	bs_weight_path_prefix <- "Put the prefix of the path to each set of bootstrap weights." # i.e. "E:/bs_weights_"
	path_to_ids_weights <- "Put the path to a csv with the first column being the \
							ids in the same order as the original dataset, and the \
							second columns containg the corresponding sample weights"

	# Read in the ids and sample weights
	ids_weights <- pd.read_csv(path_to_ids_weights, header=FALSE)
	ids <- ids_weights[ids_weights.columns[0]]
	weights <- ids_weights[ids_weights.columns[1]]

	# Create probability distribution using original sample weights
	# A) Calculate the sum of the original sample weights
	sum_of_weights <- weights.sum()
	# B) Divide the original sample weights by the sum of the original sample weights
	p_distrib <- weights/sum_of_weights


	# For the number of desired bootstrap weight sets
	for i in range(num_bootstrap_samples):

		# Randomly sample the ids using this probability distribution
		samples <- pd.Series(np.random.choice(ids, sum_of_weights, p=p_distrib))

		# For each ID count the number of times it was sampled
		bs_weights <- samples.value_counts()
		bs_weights <- bs_weights[ids]

		# Write to the bs_weight_path_prefix as a separate csv file
		write.csv(paste(bs_weight_path_prefix, i+1, ".csv", sep=""), header=FALSE)

if __name__ == '__main__':
	main()